﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;

namespace Elementum
{
    class StageDemo : Stage
    {
        public StageDemo(Game game) : base(game) { }

        public override void InitializeScenes()
        {
            base.InitializeScenes();

            Transition tra = new DefauldTransition(1, 0, 10, 60);
            tra.Register(this);
            //tra = new TitleTransition("images/title/title1", new Vector2(430, 150), 0, 1, 80, 220);//460, 391
            //tra.Register(this);

            for (int i = 1; i < 3; i++)
            {
                Animation a = new Animation("images/stages/stage2/city0" + i);
                a.LayerDepth = 0.9f;
                _backGround.Add(a);
            }
            _backGroundPos = new Vector2(-500, -500);


            //_scenceBound = new Rectangle((int)(basePos.X + 380), (int)(basePos.Y + 480),
            //       1024 * (_backGround.Count() - 1) + _backGround[_backGround.Count() - 1]._frameSize.X - 770,
            //      _backGround[0]._frameSize.Y - 620);
            _scenceBound = new Rectangle(-200, -200,
                   1400,
                  550);

            camera.Bound = _scenceBound;

            //mic = new MicSound(60);


            GroundObject grount;
         

            ProtalGate protalSwitch;
            StateFactory.CreateGround(this, 352, 440, 512, 30, 0f);
            StateFactory.CreateGround(this, 864, 440, 512, 30, 0f);
            StateFactory.CreatePortal("StageDemo_Protal_1", this, 178, 375, "stage2", "Stage2_Protal_1");
            StateFactory.CreatePortal("StageDemo_Protal_2", this, 298, 375, "stage3", "Stage3_Protal_1");
            StateFactory.CreatePortal("StageDemo_Protal_3", this, 418, 375, "stage4", "Stage4_Protal_1");
            StateFactory.CreatePortal("StageDemo_Protal_4", this, 538, 375, "stage5", "stageSnowProtal0");
            StateFactory.CreatePortal("StageDemo_Protal_5", this, 658, 375, "stage6", "Stage6_Portal_1");
            StateFactory.CreatePortal("StageDemo_Protal_6", this, 778, 375, "stage7", "Stage7_Portal_1");
            StateFactory.CreatePortal("StageDemo_Protal_7", this, 898, 375, "stage8", "Stage8Portal_1");
            StateFactory.CreatePortal("StageDemo_Protal_8", this, 1018, 375, "stage9", "Stage9_Portal_1");
            StateFactory.CreateGround(this, 48, 316, 97, 278, 0f);
            StateFactory.CreateGround(this, 1159, 336, 78, 238, 0f);

            // player = new Player(this._world, this);
            //mic.TooLoud += TestPlus;


            Font = ResourceManager.LoadSpriteFont("SpriteFont1");
            MusicManager.AddMusic("Music/doorlock", "doorlock", 0.001f, false);

            _song = MusicManager.LoadSong("Music/stageroot");
            MediaPlayer.Play(_song);
            MediaPlayer.IsRepeating = true;

            //MusicManager.AddMusic("Music/root", "first", 0.001f,true);
            // MusicManager.SetVolume("first", 0);
            //MusicManager.PlayMusic("first");
            // StateFactory.CreateSpotLight(this, 400, 80, 220, 30, -90);
            // MusicManager.AddMusic("Music/01_048", "first", 0.001f);
            // MusicManager.SetVolume("first", 0);
            // MusicManager.PlayMusic("first");

            //_bloom = new BloomComponent(Game);

        }

        public override void OnDraw(SpriteBatch spriteBatch, int delta)
        {
            base.OnDraw(spriteBatch, delta);
            //GraphicsDevice.Clear(Color.White);


            spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, null, null, null, null, camera.Transform);

            foreach (VisibleObject b in actors)
                b.OnDraw(spriteBatch, camera.Transform);

            spriteBatch.End();

            //spriteBatch.Begin();
            // spriteBatch.DrawString(Font, "" + test, new Vector2(50, 50), Color.Black);
            // spriteBatch.End();

        }

        public override void Update(int delta)
        {
            base.Update(delta);
        }

        public override Stage Clone()
        {
            StageDemo stage = new StageDemo(Game);
            stage.InitializeScenes();
            return stage;
        }

        public override void Dispose()
        {
            //mic.Dispose();
            base.Dispose();
            //mic.Dispose();
        }
    }
}
